package com.kinglone.back.sysmenu.service.impl;

import com.kinglone.back.sysmenu.dao.SysMenuMapper;
import com.kinglone.back.sysmenu.model.SysMenu;
import com.kinglone.back.sysmenu.service.SysMenuService;
import com.kinglone.common.node.ZTreeNode;
import com.kinglone.common.utils.ResultMsg;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@Service("sysMenuService")
public class SysMenuServiceImpl implements SysMenuService {

	@Resource
	private SysMenuMapper sysMenuMapper;

    /**
     * 根据top菜单获取二级菜单
     * @param topMenu
     * @return
     */
    @Override
    public List<SysMenu> getMenuByTopMenu(String topMenu) {
        return sysMenuMapper.getMenuByTopMenu(topMenu);
    }

    @Override
    public List<SysMenu> list(Map<String, Object> map) {
        return sysMenuMapper.list(map);
    }

    @Override
    public int getTotal(Map<String, Object> map) {
        return sysMenuMapper.getTotal(map);
    }

	@Override
	public ResultMsg addMenu(SysMenu sysMenu) throws Exception{
		ResultMsg msg = new ResultMsg();
		if(sysMenu.getId() == null){
            sysMenuMapper.addMenu(sysMenu);
            msg.setMessage("菜单添加成功!");
        }else{
            sysMenuMapper.updateMenu(sysMenu);
            msg.setMessage("菜单修改成功!");
        }
        msg.setSuccess(true);
        return msg;
	}

    @Override
    public void delMenu(String id) {
        sysMenuMapper.delMenu(id);
    }

    @Override
    public List<Long> getMenuIdsByRoleId(Integer roleId) {
        return sysMenuMapper.getMenuIdsByRoleId(roleId);
    }

    @Override
    public List<ZTreeNode> menuTreeList() {
        return sysMenuMapper.menuTreeList();
    }

    @Override
    public List<ZTreeNode> menuTreeListByMenuIds(List<Long> menuIds) {
        return sysMenuMapper.menuTreeListByMenuIds(menuIds);
    }

    @Override
    public List<String> getPermissionByRoleId(String roleId) {
        return sysMenuMapper.getPermissionByRoleId(roleId);
    }

}
